from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep

driver = webdriver.Firefox()
url = 'file:///C:/Users/tedu/Desktop/NSD2406/html/register.html'
driver.get(url)
sleep(3)
# 定位按钮，点击出现弹出警示框
driver.find_element(By.CSS_SELECTOR, '#alert').click()
# 弹框不处理，会影响后续的操作
sleep(3)
# 切换到弹框
alert = driver.switch_to.alert
# 接受弹框
# alert.accept()
# 取消
alert.dismiss()

sleep(3)
driver.find_element(By.CSS_SELECTOR, '#user').send_keys('admin')

sleep(3)
driver.quit()